import dataDemo from './dataDemo';

/**
 * xml经过doT.js编译出的模板函数
 * 因为小游戏不支持new Function，模板函数只能外部编译
 * 可直接拷贝本函数到小游戏中使用
 */
function tplFunc(it) {
    var out = ' <view class="container" id="main"> <view class="rankList"> <scrollview id="list" class="list" scrollY="true"> ';
    var arr1 = it.data;
    if (arr1) {
      var item, index = -1,
        l1 = arr1.length - 1;
      while (index < l1) {
        item = arr1[index += 1];
        out += '  ';
        out += ` <image class="listItem" src="openDataContext/image/bg_phb_0${index <= 2 ? index + 1 : 4}.png"> `;
        out += '  ';
        if (index >= 0 && index <= 2) {
          var i = index + 1;
          out += ` <view class="medalContainer"> <image class="medal${i}" src="openDataContext/image/icon_phb_0${i}.png"></image> </view> `;
        } else {
          out += ' <text class="listItemNum outline4" value="' + (index + 1) + '"></text> ';
        }
        out += ' ';
        out += '  <image class="listHeadImg" src="' + (item.avatarUrl) + '"> <image class="listHeadBg" src="openDataContext/image/bg_touxiangkuang_01.png"> </image> </image>  ';
        out += ' <view class="listItemUser"> '
        out += ` <text class="listItemName outline${index <= 2 ? index + 1 : 4}" value="${item.nickname}"></text> `;
        out += ` <image class="listItemScoreBg" src="openDataContext/image/bg_fenshu_0${index <= 2 ? index + 1 : 4}.png"> <text class="listItemScore" value="${item.rankScore}"></text> </image> `;
        out += ' </view> '
        out += ' </image> ';
      }
    }
    out += ' </scrollview> </view> ';
    out += ' <view class="selfItem"> '
    out += ' <image class="selfItemBg" src="openDataContext/image/bg_phb_05.png"> ';
    out += '  ';
    if (index >= 0 && index <= 2) {
      var i = index + 1;
      out += ` <view class="medalContainer"> <image class="medal${i}" src="openDataContext/image/icon_phb_0${i}.png"></image> </view> `;
    } else {
      out += ' <text class="listItemNum outline4" value="' + (index + 1) + '"></text> ';
    }
    out += ' ';
    out += '  <image class="listHeadImg" src="' + (item.avatarUrl) + '"> <image class="listHeadBg" src="openDataContext/image/bg_touxiangkuang_01.png"> </image> </image>  ';
    out += ' <view class="selfItemUser"> '
    out += ` <text class="listItemName outline${index <= 2 ? index + 1 : 4}" value="${item.nickname}"></text> `;
    out += ' <image class="listItemScoreBg" src="openDataContext/image/bg_fenshu_04.png"> <text class="listItemScore" value="' + (item.rankScore) + '"></text> </image> ';
    out += ' </view> ';
    out += ' <image class="selfItemLike" src="openDataContext/image/btn_xiaoanniu_fen_9grid.png"> ';
    out += ' <image class="selfItemLikeShare" src="openDataContext/image/icon_fenxiang.png"> </image> ';
    out += ' </image> ';
    out += ' </image> ';
    out += ' </view> ';
    out += ' </view>';

    return out;
  }

  export default tplFunc(dataDemo);